package onetotwenty;

import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;

import org.junit.Test;

public class ProjectNine {
	private boolean isPerfect(int n) {
		long l = Util.sqrt(n);
		return (n == l * l);
	}

	@Test
	public void testIsPerfectMethod() {
		assertThat(isPerfect(25), is(true));
		assertThat(isPerfect(100), is(true));
		assertThat(isPerfect(101), is(false));
		assertThat(isPerfect(102), is(false));
	}

	@Test
	public void print() {
		for (int z = 1; z <= 1000; z++) {
			int z2 = z * z;

			for (int x = 1; x * x < z2; x++) {
				int y = z2 - x * x;
				if (isPerfect(y)) {
					y = (int) Util.sqrt(y);
					if (x + y + z == 1000) {
						assertThat(x*y*z, is(31875000));
					}
				}
			}
		}
	}
}
